package com.bianmaba.beans.datacollection;

import com.bianmaba.spring.data.jpa.domain.entity.UuidIdentityEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import java.util.Calendar;
import java.util.Date;

@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TaskRunLog extends UuidIdentityEntity {
    @Column(length = 512)
    private String log;
    @Column()
    private Date datetime;

    @ManyToOne
    @JoinTable(name = "TaskLog_ref_TaskInstance")
    private TaskInstance taskInstance;

    public static TaskRunLog of(String taskInstanceId, String log) {
        return of(TaskInstance.of(taskInstanceId), log);
    }

    public static TaskRunLog of(String taskInstanceId, String log, Date datetime) {
        return of(TaskInstance.of(taskInstanceId), log, datetime);
    }

    public static TaskRunLog of(TaskInstance taskInstance, String log) {
        return of(taskInstance, log, Calendar.getInstance().getTime());
    }

    public static TaskRunLog of(TaskInstance taskInstance, String log, Date datetime) {
        return new TaskRunLog(log, datetime, taskInstance);
    }
}
